home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / DEMOS / CIRCLES.ZIP / CIRCLE.PAS next >
Encoding:
Pascal/Delphi Source File  |  1994-07-09  |  3.4 KB  |  105 lines

  1. { O.K. Sharp here with another explaination program....
  2.    This one shows how the famous moving circles is done.
  3.    The idea on how to do this was completely mine (but I ofcource wasn't
  4.    the first to do this),
  5.    it's done in EGA but if you know how to program the VGA card
  6.    you should be able to change this to VGA but DO remind yourself
  7.    that the VGA handles it's latches different than the EGA so you'll
  8.    have to change the aproach. The nice thing about it is that you can
  9.    simulate an 8 plane screen but you'l only will be able to draw 4 pixels
  10.    at a time!!. Well try it out for yourself if you figure out how to do it,
  11.    in the meanwhile stick to this:-)...
  12. }
  13.  
  14. {$G+}
  15. uses crt;
  16.  
  17. { circle.obj contains the information for the circle. Every bit is a pixel
  18.   so if a byte contains 01010101b a dotted line of 8 pixels wil be drawn.
  19.   the size is 640 x 350 bits.. (28000 bytes) }
  20. {$L circles.obj }
  21. {$F+ }
  22. procedure circleega; external;
  23. {$F- }
  24.  
  25. { draws a circle, x,y is the starting point in the buffer (left-top),
  26.   plane is the plane in which to draw the circles:
  27.   there are four planes:
  28.     plane 0 => this will result in blue circles,
  29.     plane 1 => this will result in green circles,
  30.     plane 2 => this will result in red circles,
  31.     plane 3 => this will result in gray circles...
  32.   When circles overlap the colors of the circles will be blend...}
  33.  
  34. procedure drawcircle(x,y : integer; plane : byte);
  35. label     loop1,loop2;
  36. begin
  37.   asm;
  38.     push    ds
  39.  
  40.     mov     al,02h      { mask register }
  41.     mov     ah,1
  42.     mov     cl,plane    { plane nr }
  43.     and     cl,00000011b { plane nr 0-3 !! }
  44.     shl     ah,cl       { 1 shifted by plane => mask }
  45.     mov     dx,3c4h
  46.     out     dx,ax       { out to port.. }
  47.  
  48.     mov     ax,0a000h   { VGA mem.. }
  49.     mov     es,ax       { in es. }
  50.     mov     ax,seg(circleega)    { segment containing circle data..}
  51.     mov     ds,ax       { in ds. }
  52.  
  53.     mov     di,0        { pos 0 in screen mem... }
  54.  
  55.     mov     si,x        { si => x pos }
  56.     shr     si,3        { x-pos div 8 => x-point in mem.. }
  57.     mov     ax,y        { ax => y }
  58.     mov     bx,80
  59.     mul     bx          { y * 80 => y-point in mem.. }
  60.     add     si,ax       { x+y*80 => pos. in buffer }
  61.     add     si,offset circleega  { add offset buffer.. }
  62.     mov     bx,0        { clear bx }
  63. loop1:
  64.     mov     cx,40       { 40 points in mem.. }
  65.     rep     movsb       { copy to mem. }
  66.     add     si,40       { adjust si for next line.. }
  67.     inc     bx          { next line }
  68.     cmp     bx,200      { last line reached? }
  69.     jb      loop1       { no, then do another one.. }
  70.  
  71.     pop     ds
  72.   end;
  73. end;
  74.  
  75. var  cnt        : integer;
  76.      afvang     : char;
  77.  
  78. begin
  79.   asm
  80.     mov ax,13           { 320 x 200 x 16 EGA... }
  81.     int 10h             { and make it so. }
  82.   end;
  83.  
  84.   { start with 0 degrees }
  85.   cnt:=0;
  86.  
  87.   repeat
  88.     { draw a green circle }
  89.     drawcircle(160+round(150*cos(cnt*PI / 100)),75+round(75*sin(cnt*PI / 100)),1);
  90.     { and make a gray circle }
  91.     drawcircle(160+round(75*(cos(cnt*PI / 100))+cos((50+cnt)*PI/100)),75+round(37*(sin(cnt*PI / 100)+sin((cnt+50)*PI/100))),3);
  92.  
  93.     { 200 degrees and the fun starts over...}
  94.     inc(cnt);
  95.     if cnt=200 then cnt:=0;
  96.   until keypressed;
  97.  
  98.   afvang:=readkey;      { clean da keybuffer.. }
  99.  
  100.   { and back to text mode... }
  101.   asm
  102.     mov ax,3
  103.     int 10h
  104.   end;
  105. end.